@extends('admin.layouts.base')

@section('title','控制面板')

@section('pageHeader','控制面板')

@section('pageDesc','DashBoard')

@section('content')
    <div class="row page-title-row" style="margin:5px;">
        <div class="col-md-6">
			<a href="/admin/wechatvalue/leading/{{$wid}}" class="btn btn-default btn-md">
                <i class="fa fa-file-zip-o"></i> 批量导入
            </a>
			<a href="javascript:;" class="btn btn-info btn-ed">
                <i class="fa fa-cogs"></i> 批量修改
            </a>
        </div>
        <div class="col-md-6 text-right">
			
			<a href="javascript:;" onclick="batchDel()" class="btn btn-danger btn-md" style="">
                <i class="fa fa-minus-circle"></i> 批量删除
            </a>
			<a href="/admin/wechatvalue/{{$wid}}/create" class="btn btn-success btn-md">
                <i class="fa fa-plus-circle"></i> 添加调用值
            </a>
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12">
            <div class="box">

                @include('admin.partials.errors')
                @include('admin.partials.success')
                <div class="box-body">
                    <table id="tags-table" class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th data-sortable="false" class="hidden-sm "><input id="all" type="checkbox">全选
                            </th>
                            <th class="hidden-sm">微信名称</th>
                            <th class="hidden-sm">键</th>
							<th class="hidden-sm">值</th>
                            <th class="hidden-sm">创建时间</th>
                            <th class="hidden-md">更新时间</th>
                            <th data-sortable="false">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
    <div class="modal fade" id="modal-delete" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这个调用值吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="deleteForm" method="POST" action="/admin/wechatvalue">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>

    {{--批量删除--}}
    <div class="modal fade" id="modal-batch-del" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这些调用值吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="batchDelForm" method="POST" action="/admin/wechatvalue">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>
	{{--批量修改--}}
    <div class="modal fade" id="modal-cogs-update" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">批量修改(<span style="color:red;">温馨提示：留空则不做修改。</span>)</h4>
                </div>
                <div class="modal-body">
                    <form class="batchCogsForm form-horizontal" method="POST" action="/admin/wechatvalue/cogsUpdate">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
						 <input type="hidden" name="wechat_id" value="{{ $wid }}">
						<div class="form-group">
							<label for="tagOnline_time tagOffline_time" class="col-md-2 control-label">键</label>
							<div class="col-md-9" id="keys">
								
							</div>
						</div>
						<div class="form-group">
							<label for="tagMax_rand" class="col-md-2 control-label">调用值</label>
							<div class="col-md-9">
								<input class="form-control" type="text" name="value" value="" placeholder="调用值"/>
							</div>
						</div>
                    </form>
                </div>
                <div class="modal-footer">
                    
                        <button type="button" class="btn btn-default" data-dismiss="modal">
							<i class="fa fa-times-circle"></i>  取消</button>
                        <button type="button" class="btn btn-success" onclick="$('.batchCogsForm').submit();">
                            <i class="fa fa-check-circle"></i>  确认
                        </button>
                </div>

            </div>
        </div>
    </div>
@stop

@section('js')
    <script>
        $(function () {
            var table = $("#tags-table").DataTable({
                language: {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "显示 _MENU_ 项结果",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                    "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "表中数据为空",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }
                },
                order: [[2, "desc"]],
                serverSide: true,
                ajax: {
                    url: '/admin/wechatvalue/{{$wid}}/index',
                    type: 'POST',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    }
                },
                "columns": [
                    {"data": "id"},
                    {"data": "wx_num"},
                    {"data": "key",render:function(data,type,row){ return "<span id='key_"+row['id']+"'>"+data+"</span>";}}, 
                    {"data": "value"},
                    {"data": "created_at"},
                    {"data": "updated_at"},
                    {"data": "action"}
                ],
                columnDefs: [
                    {
                        'targets': -1, "render": function (data, type, row)
                        {
                            var caozuo = '<a style="margin:3px;" href="/admin/wechatvalue/' + row['id'] + '/edit" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a>';
                            caozuo += '<a style="margin:3px;" href="#" attr="' + row['id'] + '" class="delBtn X-Small btn-xs text-danger "><i class="fa fa-times-circle-o"></i> 删除</a>';
                            
                            return caozuo;
                        }
                    },
                    {
                        'targets': 0, "render": function (data, type, row)
                        {
                            var caozuoCB = '<div class="checkbox hidden-sm"><label><input class="itemCB" name="itemCB[]" type="checkbox" value="' + row['id'] + '"></label></div>';
                            return caozuoCB;
                        }
                    }
                ]
            });

            table.on('preXhr.dt', function () {
                loadShow();
            });

            table.on('draw.dt', function () {
                loadFadeOut();
            });

            table.on('order.dt search.dt', function () {
                table.column(0, {search: 'applied', order: 'applied'}).nodes().each(function (cell, i) {
                    cell.innerHTML += (i + 1);
                });
            }).draw();

            $("table").delegate('.delBtn', 'click', function () {
                var id = $(this).attr('attr');
                $('.deleteForm').attr('action', '/admin/wechatvalue/' + id);
                $("#modal-delete").modal();
            });
			$(".btn-ed").click(function(){
				var key_input = "";
				var key_name;
				$(".itemCB").each(function () {
					if (this.checked) {
						//alert($(this).val());
						key_name = $("#key_"+$(this).val()).html();
						key_input+="<label class='label'><input name='key[]' type='checkbox' checked value='"+$(this).val()+"'/>&nbsp;<i style='color:#444444;'>"+key_name+"</i></label>";
					}
				});
				$("#keys").html(key_input);
				$('.label input').iCheck({
				  checkboxClass: 'icheckbox_square-blue',
				  radioClass: 'iradio_square-blue',
				  increaseArea: '20%' // optional
				});
				$("#modal-cogs-update").modal();
			});
        });
		
    </script>

@stop